<%@page import="sdfi.lee.DAO.UserDAO"%>
<%@page import="sdfi.lee.Entity.User"%>
<%@page import="java.util.List"%>
<%@page import="sdfi.lee.DAO.RolltypeDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="<c:url value='/css/index.css'/>" />
<link rel="stylesheet" href="<c:url value='/css/level.css'/>" />
<script type="text/javascript" src="<c:url value='/js/jquery-1.6.js'/>"></script>
<script type="text/javascript" src="<c:url value='/js/index.js'/>"></script>
<script type="text/javascript">
$(function(){
	$(".rgdiv").children(":not(:button)").attr("disabled",true);
	$("#mf").click(function(){
		if($(this).val()=="修改")
			{
			$("input[name=username]").parent().siblings(".rgdiv").children(":disabled").attr("disabled",false);
			$(this).val("取消");
			}
		else 
			{
				$(this).val("修改");
				$("input[name=username]").parent().siblings(".rgdiv").children(":not(:button)").attr("disabled",true);
			}
	});

	$("div a[index]").click(function(){
		$(this).css("color","#f00").parent("div").siblings("div").children("a").css("color","#000");
		var d="div[index="+$(this).attr("index")+']';
		
		$(d).siblings("div").hide();
		$(d).show();
				return false;
		});
	$("#rg").click(function(){
		$("#f").submit();
		});
	$(".top").click(function(){
		var ul=$(this).next("ul");
		if($(this).next("ul").children("li").size()>0)
		{
			
			if($(this).is(".topunselected"))
			{
				ul.slideDown("slow");
				$(this).removeClass("topunselected").addClass("topselected");
			}
			else
			{
				
				$(this).next("ul").slideUp("slow");
				$(this).removeClass("topselected").addClass("topunselected");
			}
		}
		else
		{
			return false;
		}
	}).addClass("topunselected");
	$(".div_myinfo ul").hide();
	$("ul li").hover(function(){
		$(this).children("span:last").show();
		},function(){
			$(this).children("span:last").hide();
			});
	/*删除*/
	$("span[rid]").live("click",function(e){
			var spthis=$(this);
			var dopt={
					url:'../DeleteCharacter',
					data:{rid:spthis.attr("rid")},
					dataType:"text",
					success:function(data,status){
						if(data=="success")
							{
								spthis.parent().remove();
								
							}
						else
							{
								alert("删除失败");
							}
					},
					error:function(status,xhr){
					
						alert("系统出错了");
					}
			}
			$.ajax(dopt);
			e.stopPropagation();
		});
	$("input[value=添加]").click(function(){
		if($('#keyword').val()==""||$('#keyword').val()==null)
				{
				 alert("对不起关键字不能为空");
				 return false;
				}
			var ge="ul[value="+$("#rolltype").val()+"]";
			if($(ge).children("li").size()>=10){
				alert("对不起每项最多只能订阅10个关键字");
				return false;
			}
			var inputb=$(this);
			var addopt12={
					url:"../AddRss",
					type:"post",
					dataType:"json",
					data:{
						keyword:$('#keyword').val(),
						rolltype:$('#rolltype').val(),
						typename:$("#rolltype").children(':selected').attr("cn")
						},
					success:function(data,status){
						if("success"==data.status){
								
								if($("ul[value="+$('#rolltype').val()+"]").children().size()>0)
									$("<li value='"+$('#rolltype').val()+"'><span>"+$('#keyword').val()+"</span>&nbsp;&nbsp;&nbsp;<span style='display:none' rid='"+data.id+"'>删除</span></li>")
									.insertAfter($("ul[value="+$('#rolltype').val()+"]").children(":last"));
								else
									{
									$("ul[value="+$('#rolltype').val()+"]").append(
											$("<li value='"+$('#rolltype').val()+"'><span>"+$('#keyword').val()+"</span>&nbsp;&nbsp;&nbsp;<span style='display:none' rid='"+data.id+"'>删除</span></li>"));
								
									}
								$("ul[value="+$('#rolltype').val()+"]").show();
								$("ul li").hover(function(){
		$(this).children("span:last").show();
		},function(){
			$(this).children("span:last").hide();
			});
						}
						else{
							alert("关键字添加失败");
						};
					},
					error:function(xhr,status){
						alert(xhr.status);
					}	
			};
			$.ajax(addopt12);
		});
});
</script>
</head>
<body>
<%
	session.setAttribute("userid",14);
	User user=new UserDAO().getUserById((Integer)session.getAttribute("userid"));
	request.setAttribute("user",user);
	RolltypeDAO rolltypedao=new RolltypeDAO();
	List<sdfi.lee.Entity.Rolltype> list=rolltypedao.getRolltype();
	request.setAttribute("rolltypes",list);
%>
<div class="divhead">当前位置:<a href="<c:url value='/index.jsp'/>">首页</a>
&gt;&nbsp;个人中心
</div>
<div id="divshowcontain">
	<div class="div_right_contain" style="height:500px;">
		<div class="div_myinfo" index="0">
			<form  id="f" action="<c:url value="/myspace/modify.action" />" method="post" >
				<div class="rgdiv">公司名：&nbsp;&nbsp;<input type="text" name="company" value="${requestScope.user.company }"/><label></label></div>
				<div class="rgdiv">联系人：&nbsp;&nbsp;<input type="text" name="linkman" value="${requestScope.user.linkman }"/><label></label></div>
				<div class="rgdiv">联系邮箱：<input type="text" name="email" value="${requestScope.user.email }"/><label></label></div>
				<div class="rgdiv">联系号码：<input type="text" name="phone" value="${requestScope.user.phone }"/><label></label></div>
				<div class="rgdiv">公司地点：<input type="text" name="address" value="${requestScope.user.address }" /><label></label></div>
				<div class="rgdiv">用户名：&nbsp;&nbsp;<input type="text" disabled="disabled" id="username" name="username" value="${requestScope.user.username }" />
				<label></label></div>
				<div class="rgdiv">密码：&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="oldpd"  value="${requestScope.user.password }" />
				<label></label></div>
				<div class="rgdiv">新密码：&nbsp;&nbsp;<input type="text" name="password" /><label></label></div>
				
 				<div class="rgdiv"><input style="width:75px;" type="button" id="mf" value="修改" />&nbsp;&nbsp;<input style="width:75px;" type="submit" id="rg" value="保存" /></div>
 			</form>	
		</div>
		<div class="div_myinfo" index="1" style="display:none">
        <fieldset style="height:450px;margin-top:10px;">
            	<legend>定制选择</legend>
                <div style="margin:10px 20px 5px 20px;padding-bottom:20px;border-bottom:1px solid #999">
                <select id="rolltype" style="padding:5px;font-size:14px;">
						<c:forEach items="${requestScope.rolltypes}" var="rolltype">
						<option value="${rolltype.id}" cn="${rolltype.typename}">
							${rolltype.typenamecn}
						</option>
						</c:forEach>
					</select>请输入关键字：<input id="keyword" style="font-size:14px;padding:5px 0px;">
                    <input style="font-size:14px;padding:3px 0px;" type="button" value="添加">
                    </div>
                    <div style="margin:10px 20px 5px 20px;">
                    <c:forEach items="${requestScope.rolltypes}" var="rolltype">
								<li class="top topunselected">
									${rolltype.typenamecn}
								</li>
									<ul value="${rolltype.id}">
									<c:forEach items="${requestScope.user.characters}" var="character">
											<c:if test="${character.rolltype.id==rolltype.id}">
											<li value="${character.rolltype.id}"><span>${character.keyword}</span>&nbsp;&nbsp;&nbsp;<span style="display:none" rid="${character.id}">删除</span></li>
											</c:if>
										
									</c:forEach>
									</ul>
							
							</c:forEach>
                            </div>
            </fieldset>
     
			
		</div>
       
      
		
	</div>
	<div class="div_left_contain">
    
		 <div class="div_left_nav" >	<a  style="color:#f00" href="#" index="0">个人中心</a></div>
		 <div class="div_left_nav" > 	<a  index="1" href="#">我的定制</a></div>
        <div style="clear:right;"></div>
	</div>
</div>
</body>
</html>